﻿using AutoMapper;
using MediatR;
using T_settlement.API.Application.Command.OutputCommand;
using T_settlement.Domain;
using T_settlement.Infrastructure.Interfacec;

namespace T_settlement.API.Application.CommandHandlers.OutputCommandHandlers
{
    public class AddOutputCommandHandlers:IRequestHandler<AddOutputCommand,int>
    {
        private readonly IOutputRepository outputRepository;
        private readonly IMapper mapper;

        public AddOutputCommandHandlers(IOutputRepository outputRepository, IMapper mapper)
        {
            this.outputRepository = outputRepository;
            this.mapper = mapper;
        }

        public async Task<int> Handle(AddOutputCommand request, CancellationToken cancellationToken)
        {
            var Info = mapper.Map<Output>(request);
            Info.InvoiceNumber = "JX" + DateTime.Now.ToString("yyyyMMddss");
            Info.CreateBy = "张三";
            Info.CreateDate = DateTime.Now;
            return await outputRepository.AddAsync(Info);

            //var Info = new Output();
            //Info.InvoiceNumber = "JX" + DateTime.Now.ToString("yyyyMMddss");
            //Info.Client = request.Client;
            //Info.InvoiceType = request.InvoiceType;
            //Info.InvoiceAmount = request.InvoiceAmount;
            //Info.Rate = request.Rate;
            //Info.Tax = request.Tax;
            //Info.Invoicetime = request.Invoicetime;
            //Info.Remark = request.Remark;
            //Info.CreateBy = "张三";
            //Info.CreateDate = DateTime.Now;

            //return await outputRepository.AddAsync(Info);
        }
    }
}
